package Algorithm;

import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.locks.ReentrantLock;

public class test222 {
    public static void main(String[] args) throws InterruptedException {
        ReentrantLock lock=new ReentrantLock();
        new Thread(()->{
            lock.lock();
            try {
                System.out.println("t1 running");
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                System.out.println("t1 unlock");
                lock.unlock();
            }
        }).start();

        Thread t2=new Thread(()->{
            try {
                lock.lock();
                System.out.println("t2 run");
            } catch (Exception e) {
                e.printStackTrace();
            }finally {
                lock.unlock();
            }
        });
        t2.start();
        Thread.sleep(1000);
        t2.interrupt();
    }
}
